//
// Created by zhou on 2021/10/29.
//
#include <iostream>
#include <vector>
using namespace std;
class Solution {
public:
    int maxProfit(vector<int>& prices) {
        int maxPro=0;
        int submax=0;
        for(int i=1;i<prices.size();i++){
            if(prices[i]>prices[i-1]){
                submax=submax+prices[i]-prices[i-1];
            }
            else {
                maxPro+=submax;
                submax=0;
            }
        }
        return maxPro+submax;
    }
    int maxProfit1(vector<int>& prices) {
        int ans = 0;
        int n = prices.size();
        for (int i = 1; i < n; ++i) {
            ans += max(0, prices[i] - prices[i - 1]);
        }
        return ans;
    }


};

int main(){
    vector<int> prices={1,2,4,3,67,4,2,65,3,1};
    Solution solution;
    cout<<solution.maxProfit(prices);
}